package org.springside.examples.showcase.wb.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springside.examples.showcase.wb.entity.WbContentRet;
import org.springside.examples.showcase.wb.service.WbContentManager;
import org.springside.modules.orm.Page;

@Controller
@RequestMapping(value = "/wb/hotrtt")
public class WbHotRttController {
	@Autowired
	private WbContentManager wbContentManager;

	@RequestMapping(value = { "list", "" })
	public String list(HttpServletRequest request, Model model) {
		String pardate = request.getParameter("pardate");
		pardate = StringUtils.isEmpty(pardate) ? "2012-02-01" : pardate;
		int pageno = 1;
		try {
			String _pageno = request.getParameter("pageno");
			pageno = Integer.parseInt(_pageno);
		} catch (NumberFormatException e) {
			pageno = 1;
		}
		Page<WbContentRet> page = new Page<WbContentRet>(10);
		page.setPageNo(pageno);
		Page<WbContentRet> hotWbs = wbContentManager.getHotWbs(page, pardate);
		model.addAttribute("hotWbs", hotWbs);
		model.addAttribute("pardate", pardate);
		model.addAttribute("pageno", pageno);
		return "wb/wbHotRtt";
	}
}
